//
//  DHAccountSettingViewController.m
//  Dresshere
//
//  Created by ZhangPeng on 2017/12/27.
//  Copyright © 2017年 张朋. All rights reserved.
//

#import "DHAccountSettingViewController.h"
#import "DHSettingControllerCell.h"
#import "DHChangePhoneViewController.h"
#import "DHChangePasswordViewController.h"

@interface DHAccountSettingViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *dataArr;

@end

@implementation DHAccountSettingViewController

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"账号设置";
    
//    self.dataArr = @[@[@"修改手机号"],@[@"实名认证"]];
    self.dataArr = @[@[@"修改手机号"]];
    
    [self.tableView registerClass:[DHSettingControllerCell class] forCellReuseIdentifier:kDHSettingControllerCell];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataArr[section] count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.dataArr count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHSettingControllerCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHSettingControllerCell forIndexPath:indexPath];
    cell.desLabel.hidden = YES;
    
    cell.titleLabel.text = self.dataArr[indexPath.section][indexPath.row];
    if (indexPath.row == [self.dataArr[indexPath.section] count] - 1) {
        cell.lineView.hidden = YES;
    }else{
        cell.lineView.hidden = NO;
    }
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        cell.desLabel.hidden = NO;
        cell.desLabel.text = [Login curLoginUser].phone;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        cell.desLabel.hidden = NO;
        cell.desLabel.text = @"已认证";
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        DHChangePhoneViewController *cpController = [[DHChangePhoneViewController alloc] init];
        [self.navigationController pushViewController:cpController animated:YES];
    }else if (indexPath.section == 1 && indexPath.row == 1){
        DHChangePasswordViewController *cpController = [[DHChangePasswordViewController alloc] init];
        [self.navigationController pushViewController:cpController animated:YES];
    }
}

//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 13;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 13)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

@end
